﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace ZhwangTool
{
   public static class Tools
    {
        public static List<string> Getfiles(string filepath, string pattern, bool? childFolder)
        {
            string p = pattern;

            List<string> f_name_list = new List<string>();

            f_name_list = System.IO.Directory.GetFiles(filepath, p, System.IO.SearchOption.TopDirectoryOnly).ToList<string>();

            if (childFolder == true)
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(filepath);

                directoryInfo.Refresh();

                foreach (System.IO.DirectoryInfo item in directoryInfo.EnumerateDirectories())
                {

                    try
                    {
                        if ((item.Attributes & FileAttributes.System) == System.IO.FileAttributes.System || (item.Attributes & FileAttributes.Hidden) == System.IO.FileAttributes.Hidden)
                        {

                        }
                        else
                        {
                            //MessageBox.Show(item.FullName + item.Attributes.ToString());

                            foreach (var fileInfo in item.GetFiles("*", System.IO.SearchOption.AllDirectories))
                            {
                                f_name_list.Add(fileInfo.FullName);

                            }

                        }

                    }
                    catch (Exception)
                    {

                        //throw;
                        continue;
                    }

                }

            }

            return f_name_list;
        }



        
    }
}
